/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pro.unal.edu.filter;

import java.awt.Color;

/**
 *
 * @author Carlos Eduardo Bernal Cárdenas
 * @version 1.0
 * @created 08-dic-2011
 */
public class GrayScaleFilter implements MyFilter {

    @Override
    public void doFilter(MyPoint[][] newImage, Color[][] colors) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Color[][] doFilter(Color[][] actualImage) {
        for (int i = 0; i < actualImage.length; i++) {
            for (int j = 0; j < actualImage[0].length; j++) {
                if (actualImage[i][j] != null && !(new Color(214, 217, 223)).equals(actualImage[i][j])) {
                    int red = Math.abs(actualImage[i][j].getRed());
                    int green = Math.abs(actualImage[i][j].getGreen());
                    int blue = Math.abs(actualImage[i][j].getBlue());
                    actualImage[i][j] = new Color((red + green + blue) / 3,(red + green + blue) / 3,(red + green + blue) / 3);
                }
            }
        }
        return actualImage.clone();
    }
}
